<table>
    <tbody>
        <tr>
            <td width="100px" class="top"><?php echo $form->label("MessageReceived.sender", "From") ?></td>
            <td>
                <?php echo $form->radio('MessageReceived.sender', array(ITS_PREFIX => 'ITS', SUPPLIER_PREFIX => 'Vendor'), array('legend' => false)); ?><br />
                <?php echo $form->hidden("MessageReceived.sender_id"); ?>
                <?php echo $form->select("MessageReceived.supplier_id", $suppliers); ?>
            </td>
        </tr>
        <tr>
            <td><?php echo $form->label("MessageReceived.send_to", "Attn.") ?></td>
            <td><?php echo $form->text("MessageReceived.send_to") ?> </td>
        </tr>
        <tr>
            <td><?php echo $form->label("MessageReceived.subject", "Subject") ?></td>
            <td>
                <?php echo $form->text("MessageReceived.subject", array('size' => 60)) ?>
            </td>
        </tr>
    </tbody>
</table>
<script type="text/javascript">
    $j(function() {
        // การเลือก send to ว่า Supplier / ITS
        $j(":radio[id*=Sender]").bind('change', function() {
            if ($j(this).is(':checked')) {
                var sender = $j(this).val();
            } else {
                var sender = null;
            }
            $j('#MessageReceivedSupplierId').hide();
            if (sender == 'its') {
                $j('#MessageReceivedSenderId').val('');
            } else if (sender == 'supplier') {
                $j('#MessageReceivedSupplierId').show().change();
            }
        }).change();

        // กำหนด sender_id ตาม ผู้รับ Supplier/Customer
        $j('#MessageReceivedSupplierId').bind('change', function() {
            var sender_id = $j(this).val();
            $j('#MessageReceivedSenderId').val(sender_id);
        });
    })
</script>

